import type { IFillText } from '../../components/app/Fill';
import type { FILL_TABLE_COLLECTION } from '../../constants/default';
import type { LanhaiFile } from '../types/file';
import type { w_sp_def, w_sp_node } from '../types/sp_def';
import type { w_sp_history } from '../types/sp_history';
import type { sys_file } from '../types/sys_file';
import type { w_zgbg, w_zgbg_ls } from '../types/zgbg';
import type { w_zgfa, w_zgfa_ls } from '../types/zgfa';
import type { w_zggk, w_zggk_ls } from '../types/zggk';
import type { w_zghy, w_zghy_ls } from '../types/zghy';
import type { w_zgtz, w_zgtz_ls } from '../types/zgtz';

export type Modules = 'all' | 'meeting' | 'programme' | 'book' | 'report' | 'rectification';

export type ValueOf<T> = T[keyof T];

export interface IRecordSchema {
  table: string
  module: string
  path: string[]
  main: boolean
  data_source: string
  pk: string
  table_desc: string
  table_name: string
  data: (sys_file | w_sp_node | w_sp_history | sys_file | w_zghy | w_zghy_ls | w_zgfa | w_zgfa_ls | w_zgtz | w_zgtz_ls | w_zgbg | w_zgbg_ls | w_zggk | w_zggk_ls | LanhaiFile)[]
}

export interface IRecordSchemas {
  [key: string]: IRecordSchema
}

export interface INodeData {
  w_sp_node: w_sp_node[]
  w_sp_history: w_sp_history[]
  sys_file: sys_file[]
}

export interface MeetingRecordData extends INodeData {
  w_zghy: w_zghy[]
  w_zghy_ls: w_zghy_ls[]
}

export interface ProgrammeRecordData extends INodeData {
  w_zgfa: w_zgfa[]
  w_zgfa_ls: w_zgfa_ls[]
}

export interface BookRecordData extends INodeData {
  w_zgtz: w_zgtz[]
  w_zgtz_ls: w_zgtz_ls[]
}

export interface ReportRecordData extends INodeData {
  w_zgbg: w_zgbg[]
  w_zgbg_ls: w_zgbg_ls[]
}

export interface RectificationRecordData extends INodeData {
  w_zggk: w_zggk[]
  w_zggk_ls: w_zggk_ls[]
}

export type RecordData = MeetingRecordData | ProgrammeRecordData | BookRecordData | ReportRecordData | RectificationRecordData;

export type ILanhaiDataSchema = Map<string, LanhaiDataSchema>;

export interface ILanhaiSpDef {
  [key: string]: w_sp_def[]
}

export interface ILanhaiSpNode {
  [key: string]: {
    [key: string]: w_sp_node
  }
}
export interface IPipe {
  import: (data: ILanhaiDataSchema, sp_def: ILanhaiSpDef, sp_node: ILanhaiSpNode, configStore: IFillText['config']) => Promise<IImportSchema[]>
  export: (sp_def: ILanhaiSpDef) => Promise<IRecordSchemas>
}

export interface ISpNode {
  [key: string]: w_sp_def
}

export interface LanhaiDataSchema {
  dataSource: string
  pk: string
  tableDesc: string
  tableName: string
  data: any[]
}

export interface IImportSchema {
  module: FILL_TABLE_COLLECTION
  main: boolean
  text: string[]
  // data: Opinion[] | OpinionProgrammeBook[] | Config[] | Record[] | Meeting[] | ActionPayload[]
  data: any[]
}
